<!--  -->
<template>
  <div class="layoutOutter">
    <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      :collapse="isCollapse"
    >
      <div class="header">
        <img src="@/images/1.jpg" alt="" class="logo" />
      </div>
      <el-menu-item
        :index="item.name"
        v-for="(item, index) in noChildren"
        :key="index"
        @click="clickMenu(item)"
      >
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
      <el-submenu  index="2" v-for="(item, index) in hasChildren" :key="index">
        <template slot="title">
          <i :class="'el-icon-' + item.icon"></i>
          <span>{{ item.ladel }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="'2-' + index1 + 1"
            v-for="(item1, index1) in item.children"
            :key="index1"
            @click="clickMenu(item1)"
            >{{ item1.label }}</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      menuData: [
        {
          path: "/",
          name: "home",
          label: "首页",
          icon: "s-home",
          url: "Home/Home",
        },
        {
          path: "/mall",
          name: "mall",
          label: "商品管理",
          icon: "s-goods",
          url: "MallManage/MallManage",
        },
        {
          path: "/user",
          name: "user",
          label: "用户管理",
          icon: "user-solid",
          url: "UserManage/UserManage",
        },
        {
          ladel: "其他",
          icon: "more",
          children: [
            {
              path: "/page1",
              name: "page1",
              label: "其他页面1",
              icon: "setting",
              url: "Other/PageOne",
            },
            {
              path: "/page2",
              name: "page2",
              label: "其他页面2",
              icon: "setting",
              url: "Other/PageTwo",
            },
          ],
        },
      ],
    };
  },
  computed: {
   
    // 有子菜单
    noChildren() {
      return this.menuData.filter((item) => !item.children);
    },
    // 没有子菜单
    hasChildren() {
      return this.menuData.filter((item) => item.children);
    },
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  methods:{
    clickMenu(item){
      console.log(item);
      this.$router.push({
        path:item.path
      })
    },
  }
};
</script>
<style lang="less" scoped>
.layoutOutter {
  height: 100vh;
}
.el-menu {
  height: 100vh;
}
.header {
    width: 100%;
    padding-top: 10px;
  .logo {
    display: block;
    margin: 0 auto;
    height: 55px;
    width: 55px;
  }
}

/* @import url(); 引入css类 */
</style>